package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class PWDDemo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入用户名");
        String name = scanner.nextLine();

        System.out.println("请输入新的密码");
        String password = scanner.nextLine();

        System.out.println("请输入新的昵称");
        String nickname = scanner.nextLine();

        System.out.println("请输入新的年龄");
        int age = Integer.parseInt(scanner.nextLine());
        System.out.println(name + "," + password + "," + nickname + "," + age);

        try(
                Connection connection = DBUtil.getConnection()
        ){
            Statement statement = connection.createStatement();
            String sql = "INSERT INTO user(name,password,nickname,age)" +
                    "VALUES('" + name + "','" + password + "',' " + nickname +"',"  + age + ")";
            System.out.println(sql);
            int num = statement.executeUpdate(sql);
            System.out.println("插入完毕，影响了表中：" + num + "条记录");
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
